package inv.stask.ui;

import inv.stask.beans.Task;
import inv.stask.beans.Task.Priority;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;

public class TaskRowRenderer extends DefaultTableCellRenderer {


	private static final long serialVersionUID = -4652643526136617958L;

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int viewRow, int column) {
		
		int modelRow = table.convertRowIndexToModel(viewRow);
		Component c =  super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
				viewRow, column);
		
		TableModel tableModel = table.getModel();
		if(tableModel instanceof TaskListTableModel){
			Task task = ((TaskListTableModel)tableModel).getTaskList().get(modelRow);
			if(Priority.HIGH.equals(task.getPriority())){
					c.setFont(getFont().deriveFont(Font.BOLD));
			}else
				if(Priority.LOW.equals(task.getPriority())){
						c.setFont(getFont().deriveFont(Font.ITALIC));
				}
			
			if(task.getDone()){
					c.setForeground(Color.GRAY);
			}else{
					c.setForeground(Color.BLACK);
			}
			
		}
		
		return c;
	}
	
}
